package de.uniba.wiai.lspi.chord.service.impl;

import java.util.HashSet;
import java.util.Vector;

import de.uniba.wiai.lspi.chord.com.Entry;
import fusion.FusionEntry;

public class FusedEntry extends WCNode {
	private int refCount;
	private FusedAuxNode[] auxNode;
	public FusionEntry fusionEntry = null;
	
	public FusedEntry(int numPrimaries){
		auxNode = new FusedAuxNode[numPrimaries];
		fusionEntry = new FusionEntry(numPrimaries, 1, 0);
	}

	public int[] getCodeValue() {
		return fusionEntry.getCode();
	}
	public FusedAuxNode[] getAuxNode() {
		return auxNode;
	}
	public void setAuxNode(int primaryId, FusedAuxNode auxNode) {
		this.auxNode[primaryId] = auxNode;
	}

	public void addElement(HashSet<Entry> newElement, int primaryId, int backupId){
		fusionEntry.updateCodes(null, newElement, primaryId);
		++refCount;
	}

	public void removeElement(HashSet<Entry> oldElement, int primaryId, int backupId){
		fusionEntry.updateCodes(oldElement, null, primaryId);
		--refCount;
	}
	public boolean isEmpty(){
		if(refCount ==0)
			return true;
		else
			return false; 
	}

	public String toString(){
		int [] code = fusionEntry.getCode();
		Vector<Integer> codeV = new Vector<Integer>();
		for (int i = 0; i < code.length; ++i) {
			codeV.add(code[i]);
		}
		
		return ("[" + codeV.hashCode() + "]");
	}
}
